Exemplo de análise

Introdução

Pacotes do R necessários

library(readr) # Leitura de arquivos CSV
library(dplyr) # Manipulação de dados
library(glue) # Manipulação de texto
library(lubridate) # Conversão de datas
library(ggplot2) # Gráficos
library(gghighlight) # Destaque em gráficos

Leitura dos arquivos de dados

Definição do município

Defina abaixo a sigla do seu estado, o código do seu município e nome. Uma tabela de códigos de municípios pode ser encontrada aqui.

sigla_estado <- "RJ"
cod_mun <- 3303401
nome_mun = "Nova Friburgo, RJ"

Dados de clima

# Temperatura máxima
temp_max <- read_csv2(
  file = glue("export/clima/tmax/tmax_{tolower(sigla_estado)}.csv")
) |>
  filter(code_muni == cod_mun)

# Normal climatológica da temperatura máxima
temp_max_normal <- read_csv2(
  file = glue(
    "export/clima/tmax_normal/tmax_normal_{tolower(sigla_estado)}.csv"
  )
) |>
  filter(code_muni == cod_mun)

# Temperatura mínima
temp_min <- read_csv2(
  file = glue("export/clima/tmin/tmin_{tolower(sigla_estado)}.csv")
) |>
  filter(code_muni == cod_mun)

# Normal climatológica da temperatura mínima
temp_min_normal <- read_csv2(
  file = glue(
    "export/clima/tmin_normal/tmin_normal_{tolower(sigla_estado)}.csv"
  )
) |>
  filter(code_muni == cod_mun)

# Precipitação
prec <- read_csv2(
  file = glue("export/clima/prec/prec_{tolower(sigla_estado)}.csv")
) |>
  filter(code_muni == cod_mun)

# Normal climatológica da precipitação
prec_normal <- read_csv2(
  file = glue(
    "export/clima/prec_normal/prec_normal_{tolower(sigla_estado)}.csv"
  )
) |>
  filter(code_muni == cod_mun)

# Umidade relativa
rh <- read_csv2(
  file = glue("export/clima/rh/rh_{tolower(sigla_estado)}.csv")
) |>
  filter(code_muni == cod_mun)

# Normal climatológica da umidade relativa
rh_normal <- read_csv2(
  file = glue(
    "export/clima/rh_normal/rh_normal_{tolower(sigla_estado)}.csv"
  )
) |>
  filter(code_muni == cod_mun)

Dados ambientais

ambiental <- read_csv2(
  file = glue(
    "export/ambiental_mensal/ambiental_mensal_{tolower(sigla_estado)}.csv"
  )
) |>
  filter(code_muni == substr(cod_mun, 0, 6))
ℹ Using "','" as decimal and "'.'" as grouping mark. Use `read_delim()` for more control.
Rows: 72864 Columns: 6
── Column specification ────────────────────────────────────────────────────────
Delimiter: ";"
chr (1): code_ind
dbl (5): code_uf, code_muni, ano, mes, valor

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Dados IBGE

ibge <- read_csv2(
  file = glue(
    "export/ibge/ibge_{tolower(sigla_estado)}.csv"
  )
) |>
  filter(code_muni == substr(cod_mun, 0, 6))
ℹ Using "','" as decimal and "'.'" as grouping mark. Use `read_delim()` for more control.
Rows: 39560 Columns: 5
── Column specification ────────────────────────────────────────────────────────
Delimiter: ";"
chr (1): code_indi
dbl (4): code_uf, code_muni, ano, valor

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Dados Proadess

proadess <- read_csv2(
  file = glue(
    "export/proadess/proadess_{tolower(sigla_estado)}.csv"
  )
) |>
  filter(code_muni == substr(cod_mun, 0, 6))
ℹ Using "','" as decimal and "'.'" as grouping mark. Use `read_delim()` for more control.
Rows: 9200 Columns: 5
── Column specification ────────────────────────────────────────────────────────
Delimiter: ";"
chr (1): code_indi
dbl (4): code_uf, code_muni, ano, valor

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Dimensão climática

temp_max |>
  mutate(
    mes = month(mes, label = TRUE, abbr = TRUE)
  ) |>
  ggplot(aes(x = mes, y = valor, group = ano)) +
  geom_line(color = "red") +
  gghighlight(ano == 2024, use_group_by = FALSE) +
  theme_bw() +
  labs(
    title = "Médias das temperaturas máximas desde 1950",
    y = "Graus celsius",
    subtitle = nome_mun
  )

temp_min |>
  mutate(
    mes = month(mes, label = TRUE, abbr = TRUE)
  ) |>
  ggplot(aes(x = mes, y = valor, group = ano)) +
  geom_line(color = "blue") +
  gghighlight(ano == 2024, use_group_by = FALSE) +
  theme_bw() +
  labs(
    title = "Médias das temperaturas mínimas desde 1950",
    y = "Graus celsius",
    subtitle = nome_mun
  )

rh |>
  mutate(
    mes = month(mes, label = TRUE, abbr = TRUE)
  ) |>
  ggplot(aes(x = mes, y = valor, group = ano)) +
  geom_line(color = "coral4") +
  gghighlight(ano == 2024, use_group_by = FALSE) +
  theme_bw() +
  labs(
    title = "Média da umidade relativa desde 1950",
    subtitle = nome_mun,
    y = "%"
  )

prec |>
  mutate(
    mes = month(mes, label = TRUE, abbr = TRUE)
  ) |>
  ggplot(aes(x = mes, y = valor, group = ano)) +
  geom_line(color = "darkblue") +
  gghighlight(ano == 2024, use_group_by = FALSE) +
  theme_bw() +
  labs(
    title = "Média da precipitação desde 1950",
    subtitle = nome_mun,
    y = "mm"
  )

Dimensão ambiental

ambiental |>
  filter(code_ind == "to0043") |>
  mutate(
    mes = month(mes, label = TRUE, abbr = TRUE)
  ) |>
  ggplot(aes(x = mes, y = valor, group = ano)) +
  geom_line(color = "darkblue") +
  gghighlight(ano == 2024, use_group_by = FALSE) +
  theme_bw() +
  ylim(0, 1) +
  labs(
    title = "Índice de estado da vegetação (NDVI) médio",
    subtitle = nome_mun,
    y = "NDVI"
  )
label_key: ano

ambiental |>
  filter(code_ind == "to0011") |>
  mutate(
    mes = month(mes, label = TRUE, abbr = TRUE)
  ) |>
  ggplot(aes(x = mes, y = valor, group = ano)) +
  geom_line(color = "darkblue") +
  gghighlight(ano == 2024, use_group_by = FALSE) +
  theme_bw() +
  labs(
    title = "Concentração média de material particulado fino na atmosfera",
    subtitle = nome_mun,
    y = "Concentração"
  )
label_key: ano

ambiental |>
  filter(code_ind == "to0012") |>
  mutate(
    mes = month(mes, label = TRUE, abbr = TRUE)
  ) |>
  ggplot(aes(x = mes, y = valor, group = ano)) +
  geom_line(color = "darkblue") +
  gghighlight(ano == 2024, use_group_by = FALSE) +
  theme_bw() +
  labs(
    title = "Concentração média de monóxido de carbono na atmosfera",
    subtitle = nome_mun,
    y = "Concentração"
  )
label_key: ano

Dimensão SUS

proadess |>
  filter(code_indi == "proadess001") |>
  ggplot(aes(x = as.character(ano), y = valor)) +
  geom_bar(fill = "darkblue", stat = "identity") +
  # gghighlight(ano == 2024, use_group_by = FALSE) +
  theme_bw() +
  coord_flip() +
  labs(
    title = "Número de enfermeiros, por 100 mil habitantes",
    subtitle = nome_mun,
    y = "Contagem",
    x = "Ano"
  )

proadess |>
  filter(code_indi == "proadess002") |>
  ggplot(aes(x = as.character(ano), y = valor)) +
  geom_bar(fill = "darkblue", stat = "identity") +
  # gghighlight(ano == 2024, use_group_by = FALSE) +
  theme_bw() +
  coord_flip() +
  labs(
    title = "Número de médicos, por 1.000 habitantes",
    subtitle = nome_mun,
    y = "Contagem",
    x = "Ano"
  )

proadess |>
  filter(code_indi == "proadess003") |>
  ggplot(aes(x = as.character(ano), y = valor)) +
  geom_bar(fill = "darkblue", stat = "identity") +
  # gghighlight(ano == 2024, use_group_by = FALSE) +
  theme_bw() +
  coord_flip() +
  labs(
    title = "Número de leitos hospitalares\n(excluídos os psiquiátricos), por 1.000 habitantes",
    subtitle = nome_mun,
    y = "Contagem",
    x = "Ano"
  )

proadess |>
  filter(code_indi == "proadess005") |>
  ggplot(aes(x = as.character(ano), y = valor)) +
  geom_bar(fill = "darkblue", stat = "identity") +
  # gghighlight(ano == 2024, use_group_by = FALSE) +
  theme_bw() +
  coord_flip() +
  labs(
    title = "Densidade demográfica",
    subtitle = nome_mun,
    y = "Contagem",
    x = "Ano"
  )

proadess |>
  filter(code_indi == "proadess006") |>
  ggplot(aes(x = as.character(ano), y = valor)) +
  geom_bar(fill = "darkblue", stat = "identity") +
  # gghighlight(ano == 2024, use_group_by = FALSE) +
  theme_bw() +
  coord_flip() +
  labs(
    title = "Percentual de internações por Condições Sensíveis à Atenção Primária",
    subtitle = nome_mun,
    y = "Contagem",
    x = "Ano"
  )